package org.seler.spring.ioc.AdditionalCapabilities;

import java.util.List;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

public class EmailService implements ApplicationEventPublisherAware {

	  private List<String> blackList;
	  private ApplicationEventPublisher publisher;

	  public void setBlackList(List<String> blackList) {
	      this.blackList = blackList;
	  }

	  public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
	      this.publisher = publisher;
	  }

	  public void sendEmail(String address, String text) {
	      if (blackList.contains(address)) {
	          BlackListEvent event = new BlackListEvent(this, address, text);
	          publisher.publishEvent(event);
	          return;
	      }
	      // send email...
	      System.out.println("send email...");
	  }
	}